package ro.bluecube.admlocal.gui.users;

import java.util.ArrayList;

import ro.bluecube.admlocal.gui.commons.SortTableModel;
import ro.bluecube.admlocal.users.entity.User;

public class UsersTableModel extends SortTableModel {
	private static final long serialVersionUID = 1L;
	
	public static final int INDEX_NAME = 0; 
	public static final int INDEX_PASSWORD = 1; 
	public static final int INDEX_PERSON = 2;

	private User userData;
	
	public UsersTableModel(ArrayList tableData) {
		super(tableData);
		ArrayList<String> columnNames = new ArrayList<String>();
		columnNames.add("Nume");
		columnNames.add("Parola");
		columnNames.add("Persoana");
		setColumnNames(columnNames);
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		userData = (User) getTableData().get(rowIndex);
		if (columnIndex == INDEX_NAME){
			return userData.getUserName();
		} else if (columnIndex == INDEX_PASSWORD){
			return userData.getPassword();
		} else if (columnIndex == INDEX_PERSON){
			return userData.getPerson().getFirstName();
		} 
		
		return "";
	}
	
	public User getUser(int index){
		if (index>=0){
			return (User) getTableData().get(index);
		}
		return null;
	}
}
